package com.csu.controller;

import com.alibaba.fastjson.JSON;
import com.csu.common.CommonResponse;
import com.csu.domain.Order;
import com.csu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/orders")
    public CommonResponse<List<Order>> selectAllOrders(){
        return orderService.selectAllOrders();
    }

    @PutMapping("/status")
    public CommonResponse<Object> editStatus(@RequestBody Order order){
        return orderService.editStatus(order);

    }
//
////    @PostMapping("/orderInfo")
////    public List<Order> orderInfo() {
////        return orderService.selectAllOrder();
////    }
//
//    @RequestMapping("/json_order")
//    @ResponseBody
//    public String selectAllOrder() {
//        List<Order> orders = orderService.selectAllOrder();
//        String length = Integer.toString(orders.size());
//        String jsonString = JSON.toJSONString(orders);
//        return "{\"code\":\"0\",\"msg\":\"ok\",\"count\":\"" + length + "\",\"data\":" + jsonString + "}";
//    }
//
//    @GetMapping("/deleteOrder")
//    @ResponseBody
//    public String deleteOrder(@RequestParam("id")int id){
//        orderService.deleteOrderById(id);
//        orderService.updateOrder(id);
//        return "success";
//    }
//
//    @PutMapping("/editOrder")
//    @ResponseBody
//    public String editOrder(@ModelAttribute Order order){
//        orderService.editOrder(order);
//        return "success";
//    }
//
//    @GetMapping("/searchAllOrder")
//    @ResponseBody
//    public String searchAllOrder(String content){
//        List<Order> orders = orderService.searchAllOrder(content);
//        String length = Integer.toString(orders.size());
//        String jsonString = JSON.toJSONString(orders);
//        return "{\"code\":\"0\",\"msg\":\"ok\",\"count\":\"" + length + "\",\"data\":" + jsonString + "}";
//    }
//
//    //弹窗
//    @GetMapping("/updateOrder")
//    public String updateOrder(){
//        return "updateOrder";
//    }
}



